home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / mhs_c.arc / INPOST.ARC / INPOST.C < prev    next >
C/C++ Source or Header  |  1988-06-27  |  5KB  |  251 lines

  1. /* (C) Copyright 1987,1988 - TaxWare/Neil W. Taylor */
  2.  
  3. #include "cctypes.h"
  4. #define WORKSPACE 2000
  5.  
  6. /* ****************** GLOBAL VARIABLES ****************** */
  7. int Dbug = 0;
  8. int comType = 0;
  9. int answer = 0;
  10. int NotMergeFileNamePtr = -1;
  11.  
  12. int ErrorsInThisFile = 0;
  13. int WarningsInThisFile = 0;
  14. int warningFound;
  15.  
  16. int InFile;
  17. int OutFile;
  18. FILE *CCHandle;
  19. char InFileName[256];
  20. char OutFileName[256];
  21. char workArea[64]; /* argv[6] */
  22. char messageBuffer[8192];
  23.  
  24. MCB MCBStruct;
  25.  
  26. int lineNumber = 0, lNumber = 0;
  27.  
  28. char Out[WORKSPACE];
  29. char originatingHost[37];
  30. long fileSize = 0;
  31.  
  32. char InExtension[] = ".EXP";
  33. char OutExtension[] = ".MCB";
  34.  
  35. char *CommandTypes[] = {
  36.     "",
  37.     "Message:",
  38.     "Contents:",
  39.     "From:",
  40.     "Forward",
  41.     "Date:",
  42.     "To:",
  43.     "cc:",
  44.     "Subject:",
  45.     "Text ",
  46.     "Graphic",
  47.     "File",
  48.     0
  49. };
  50.  
  51. char *ErrorTypes[] = {
  52.     "Unknown Error",
  53.     "Syntax",
  54.     "Cannot Open File",
  55.     "Cannot Create Output",
  56. };
  57.  
  58. struct {
  59.     char name[40];
  60.     char loc[10];
  61.     char addr[80];
  62.     char comment[80];
  63. } CCRec;
  64.  
  65. void    UpperCase();
  66. int        Parse();
  67. extern int        OpenInputFile();
  68. extern int        OpenOutputFile();
  69. int        GetCommandType();
  70. int        GetParameter();
  71. int        SetUpOutFile();
  72. void    FinishUpOutFile();
  73. void    Error();
  74. void    Warning();
  75. int        MergeIt();
  76. void    InitMCB();
  77.  
  78. void WriteLine();
  79.  
  80. void main(argc, argv)
  81. int argc;
  82. char *argv[];
  83. {
  84.     int exitCode = ERROR_ENCOUNTERED, ccode, i;
  85.     char commandLine[256], command[80], *p;
  86.  
  87.     system("CLS");
  88.     for ( i = 1; i < 6; i++ )
  89.         WriteLine("\0");
  90.  
  91.     WriteLine("   cc:Mail / MHS Gateway\0");
  92.     WriteLine("\0");
  93.     WriteLine("   Converting message(s) to MHS format...\0");
  94.     WriteLine("\0");
  95.  
  96.  
  97.     if (argc != 7 ) goto Out;
  98.  
  99.     sprintf(commandLine, "Z:MAP P:=%s > NUL:", argv[4]);
  100.     system(commandLine);
  101.  
  102.     strcpy(workArea, "P:");
  103.  
  104.     sprintf(commandLine, "Z:EXPORT %s %s %s @%s directory > NUL:",argv[1],
  105.             argv[3], workArea, workArea);
  106.     system(commandLine);
  107.  
  108.     CCHandle = fopen("P:CCMDIR.EXP", "r");
  109.     if ( CCHandle == NULL )
  110.         goto Out;
  111.  
  112. ExportNext:
  113.  
  114.     p = fgets(CCRec.name,
  115.         sizeof(CCRec.name),                    
  116.         CCHandle);
  117.     if ( p == NULL ) goto Out;
  118.  
  119.     p = fgets(CCRec.loc, sizeof(CCRec.loc), CCHandle);
  120.     p = fgets(CCRec.addr, sizeof(CCRec.addr), CCHandle);
  121.     p = fgets(CCRec.comment, sizeof(CCRec.comment), CCHandle);
  122.     if ( CCRec.loc[6] != 'P' ) goto ExportNext;
  123.     UpperCase(&CCRec.addr[6]);
  124.     if ( CCRec.addr[6] == 'M' && CCRec.addr[7] == 'H' && CCRec.addr[8] == 'S' )
  125.         goto DoIt;
  126.     else
  127.         goto ExportNext;
  128.  
  129. DoIt:
  130.  
  131.     CCRec.name[strlen(CCRec.name)-1] = '\0';
  132.     sprintf(commandLine, "Z:\EXPORT %s %s %s @%s >NUL:",&CCRec.name[6],
  133.             argv[3], workArea, workArea);
  134.     system(commandLine);
  135.  
  136.     sprintf(InFileName, "%sCCMAIL.EXP", workArea);
  137.  
  138.     /* convert filename to upper case */
  139.     UpperCase(InFileName);
  140.  
  141.     /* Convert CC to MCB */
  142.  
  143.     ccode = OpenInputFile();
  144.     if ( ccode == -1 ) {
  145. /*         Error(CANNOT_OPEN_FILE); */
  146.         unlink("P:CCMAIL.EXP");
  147.         goto ExportNext;
  148.     }
  149.  
  150.     strcpy(originatingHost, argv[2]);
  151.  
  152.     InitMCB();
  153.  
  154.     /* PARSE the temporary file CCMAIL.EXP created by the EXPORT utility */
  155.     ccode = Parse();
  156.     if ( ccode ) /* CANNOT_CREATE_OUTPUT or FATAL_ERROR_ENCOUNTERED */
  157.         goto CloseInput;
  158.  
  159.     if ( ccode == NO_ERROR ) {
  160.         close(InFile);
  161.         WriteMCBFile();
  162.         /* STUB take out the -V later */
  163.  
  164.         sprintf(commandLine, "Z:\SEAL -F%sCCMAIL.MCB -V >NUL:", workArea);
  165.         system(commandLine);
  166.  
  167.         /* now delete the CCMAIL.* files in the workarea */
  168.         unlink("P:CCMAIL.ANS");
  169.         close(InFile);
  170.         unlink("P:CCMAIL.EXP");
  171.         goto ExportNext;
  172.     }
  173.  
  174. CloseInput:
  175.     close(InFile);
  176.     goto ExportNext;
  177. Out:
  178.     exitCode = NO_ERROR; /* ?? */
  179.     fclose(CCHandle);
  180.     unlink("P:CCMDIR.EXP");
  181.     system("CLS");
  182.     exit(exitCode);
  183. }
  184.  
  185. void EOL(string)
  186. char *string;
  187. {
  188. /*     string[0] = '\15';
  189.     string[1] = '\12';
  190.     string[2] = '\0'; */
  191. /*     strcpy(string, "\15\12"); */
  192.     string[0] = '\0';
  193. }
  194.  
  195. void InitMCB()
  196. {
  197.     /* 1 */
  198.     strcpy(MCBStruct.MHSVersion, "MHS-1");
  199.     /* 2 */
  200.     MCBStruct.headerLines = 18;
  201.     /* 3 */
  202.     MCBStruct.MCBType = 0; /* message MCB */
  203.     /* 4 */
  204.     EOL(MCBStruct.deliveryOptions);
  205.     /* 5 */
  206. /*     EOL(MCBStruct.originatingApplicationName); */
  207.     strcpy(MCBStruct.originatingApplicationName, "EMAIL");
  208.     /* 6 */
  209.     EOL(MCBStruct.originatingUsername);
  210.     /* 7 */
  211. /*     EOL(MCBStruct.originatingHost); */
  212.     strcpy(MCBStruct.originatingHost, originatingHost);
  213.     /* 8 */
  214.     EOL(MCBStruct.destinationUsername);
  215.     /* 9 */
  216.     EOL(MCBStruct.destinationHost);
  217.     /* 10 */
  218.     EOL(MCBStruct.messageSubject);
  219.     /* 11 */
  220.     EOL(MCBStruct.attachmentFilename);
  221.     /* 12 */
  222.     EOL(MCBStruct.sealedMessageID);
  223.     /* 13 */
  224.     EOL(MCBStruct.referencedMessageID);
  225.     /* 14 */
  226.     EOL(MCBStruct.dateSealed);
  227.     /* 15 */
  228.     EOL(MCBStruct.dateUnsealed);
  229.     /* 16 */
  230.     MCBStruct.contentTypeOfAttachmentFile = 0; /* no file */
  231.     /* 17 */
  232.     MCBStruct.statusReport = 0;
  233.     /* 18 */
  234.     EOL(MCBStruct.blankLine);
  235.  
  236.     messageBuffer[0] = '\0';
  237. }
  238.  
  239. void WriteLine(string)
  240. char *string;
  241. {
  242. /*     char line[80], temp[79];
  243.  
  244.     strncpy(temp, "                                                                      ",
  245.             76-strlen(string));
  246.     sprintf(line, "│%s%s\n", string, temp);
  247.     printf(line); */
  248.     printf("%s\n",string);
  249. }
  250.  
  251.